//package com.example.file_management.controller;
//
//import com.example.file_management.service.FileService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.nio.file.Paths;
//import java.util.Map;
//
//@RestController
//@RequestMapping("/api/files")
////public class FileController {
//
//    @Autowired
//    private FileService fileService;
//
//    // 上传文件（保持原始格式）
//    @PostMapping("/upload")
//    public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile file) {
//        try {
//            String fileName = fileService.uploadFile(file);
//            return ResponseEntity.ok(Map.of("fileName", fileName));
//        } catch (Exception e) {
//            return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
//        }
//    }
//
//    // 预览文件（动态转换为 PDF）
//    @GetMapping(value = "/preview", produces = MediaType.APPLICATION_PDF_VALUE)
//    public ResponseEntity<?> previewFile(@RequestParam String fileName) {
//        try {
//            String pdfFileName = fileService.convertToPDFForPreview(fileName);
//            var pdfFile = Paths.get("E:/filestest/", pdfFileName).toFile();
//            return ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(pdfFile);
//        } catch (Exception e) {
//            return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
//        }
//    }
//}
